package com.hustzp.com.xichuangzhu.me;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.TextView;

import com.hustzp.com.xichuangzhu.MainActivity;
import com.hustzp.com.xichuangzhu.R;
import com.hustzp.com.xichuangzhu.XichuangzhuApplication;

import java.util.Locale;

/**
 * Created by Administrator on 2016/6/5.
 */
public class SwitchFontTypeActivity extends MyBaseActivity {

    private TextView simpleFont;
    private TextView complexFont;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_switch_font_type);

        initToolbar();
        initViews();
    }

    private void initToolbar() {
        TextView navTxt = (TextView) findViewById(R.id.tv_nav_txt);
        navTxt.setText(getString(R.string.setting));
        TextView appTitle = (TextView) findViewById(R.id.tv_title_txt);
        appTitle.setText(getString(R.string.tw_or_chines));
    }

    private void initViews() {
        simpleFont = (TextView) findViewById(R.id.choose_simple_font);
        complexFont = (TextView) findViewById(R.id.choose_complex_font);

        String ftv = XichuangzhuApplication.getInstance().getFanjian();
        if ("1".equals(ftv)) {
            simpleFont.setVisibility(View.VISIBLE);
            complexFont.setVisibility(View.GONE);
        } else {
            //繁体
            complexFont.setVisibility(View.VISIBLE);
            simpleFont.setVisibility(View.GONE);
        }
    }

    public void clickView(View view) {
        switch (view.getId()) {
            case R.id.simple_font_btn:
                simpleFont.setVisibility(View.VISIBLE);
                complexFont.setVisibility(View.GONE);
                XichuangzhuApplication.getInstance().saveFanjian("1");

                Configuration config = getResources().getConfiguration();
                DisplayMetrics dm = getResources() .getDisplayMetrics();
                config.locale = Locale.SIMPLIFIED_CHINESE;
                getResources().updateConfiguration(config, dm); //强制设置语言类

                Intent intent = new Intent(this, MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
               startActivity(intent);
                break;
            case R.id.complex_font_btn:

                Configuration configTAIWAN = getResources().getConfiguration();
                DisplayMetrics dmTAIWAN = getResources() .getDisplayMetrics();
                configTAIWAN.locale = Locale.TAIWAN;
                //强制设置语言类
                getResources().updateConfiguration(configTAIWAN, dmTAIWAN);
                complexFont.setVisibility(View.VISIBLE);
                simpleFont.setVisibility(View.GONE);
                XichuangzhuApplication.getInstance().saveFanjian("2");

                Intent mainActivity = new Intent(this, MainActivity.class);
                mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(mainActivity);

                break;
        }
    }
}
